<?php
/**
 * Created by PhpStorm.
 * User: chen
 * Date: 18-6-9
 * Time: 上午10:39
 */

namespace App\Http\Controllers\Core;

use App\Http\Controllers\Controller;
use App\Model\Common\Position;
use App\ServiceHandler\Common\PositionService;
use App\Tool\Error;
use http\Env\Request;

class PostionController extends Controller
{
    /**
     * 添加
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function addPosition(Request $request){
        $result = PositionService::post($request->all());
        if($result){
            return $this->success();
        }
        return $this->error(Error::POSITION_ADD_FAILD);
    }

    /**
     * 删除
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function deletePosition(Request $request){
        $result  = Position::destroy($request['id']);
        if($result){
            return $this->success();
        }
        return $this->error(Error::POSITION_DEL_FAILD);
    }


    /**
     * 编辑
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function editPositon(Request $request){
        $result = PositionService::post($request->all());
        if($result){
            return $this->success();
        }
        return $this->error(Error::POSITION_EDIT_FAILD);
    }

    /**
     * 查询
     * @return mixed
     */
    public function queryPosition(){
        return Position::paginate(Position::per_page());
    }
}